package de.slothsoft.wasbinich.android.free;

import android.util.Log;
import android.view.ViewGroup;

import com.google.android.gms.ads.AdView;

import de.slothsoft.wasbinich.android.AbstractActivity;
import de.slothsoft.wasbinich.android.QuestionActivity;

public class AdvertizingCallBack extends AbstractActivity.CallBack {

    private AdView adView;

    @Override
    public void onCreate(AbstractActivity activity) {
	if (activity instanceof QuestionActivity)
	    return;

	ViewGroup layoutView = (ViewGroup) activity.getLayoutView();
	this.adView = AdvertizingUtil.createAd(activity, layoutView);

	if (this.adView != null) {
	    Log.d("slothsoft", "Adding advertizing to " + layoutView.getClass()); //$NON-NLS-1$ //$NON-NLS-2$
	} else {
	    Log.w("slothsoft", "Could not add advertizing to layout " + (layoutView == null ? null : layoutView.getClass())); //$NON-NLS-1$ //$NON-NLS-2$
	}
    }

    @Override
    public void onPause(AbstractActivity activity) {
	if (this.adView != null) {
	    this.adView.pause();
	}
    }

    @Override
    public void onResume(AbstractActivity activity) {
	if (this.adView != null) {
	    this.adView.resume();
	}
    }

    @Override
    public void onDestroy(AbstractActivity activity) {
	if (this.adView != null) {
	    this.adView.destroy();
	}
    }

}
